{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">添加车辆</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="{:url('bus/handle')}" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属车队</label>
                    <div class="layui-input-inline">
                        <select name="business_id">
                            <option value="">请选择车队</option>
                            {foreach $business as $key=>$val}
                                <option value="{$val.id}" {if $info.business_id == $val.id}selected{/if} >{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">车牌号码</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.bus_no|default=''}" name="bus_no" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">座位数</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.seat_num|default=''}" name="seat_num" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">注册时间</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.begin_time|default=''}" id="begin_time" name="begin_time" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">车辆品牌</label>
                    <div class="layui-input-inline">
                        <select name="brand_id">
                            <option value="">请选择车辆品牌</option>
                            {foreach $brand_list as $key=>$val}
                                <option value="{$val.id}" {if $info.brand_id == $val.id}selected{/if} >{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">行驶证</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="driving_license_btn">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="driving_license_img" src="{$info->driving_license |default=''}">
                            <p id="test-upload-demoText"></p>
                        </div>
                    </div>
                </div>
                <style>

                    .layui-col-xs3 {
                        width: auto;
                    }

                    img {
                        width: 92px;
                        /*height: 92px;*/
                        margin: 0 10px 10px 0;
                        border: 1px solid #e6e6e6;
                    }
                </style>
                <div class="layui-form-item">
                    <label class="layui-form-label">车辆实拍</label>
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="bus_img_btn">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                            <input class="layui-upload-file" type="file" accept="undefined" name="file" multiple="">
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                <div class="layui-upload-list">
                                    <div class="layui-row" id="pic-list">
                                        {if count($info->imgs) > 0}
                                            {foreach $info->imgs as $key=>$val}
                                                <div class="layui-col-xs3">
                                                    <img src="{$val->img}" class="layui-upload-img" data-src="{$val->getData('img')}">
                                                    <p id="demoText">
                                                        <button type="button" class="layui-btn layui-btn-xs demo-reload">
                                                            删除
                                                        </button>
                                                    </p>
                                                </div>
                                            {/foreach}
                                        {/if}
                                    </div>
                                </div>
                            </blockquote>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="status" value="1" {if $info->status == 1}checked{/if} title="开启">
                        <input type="radio" name="status" value="0" {if $info->status == 0}checked{/if} title="关闭">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">审核状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="state" value="1" {if $info->getData('state') == 1}checked{/if} title="审核中">
                        <input type="radio" name="state" value="2" {if $info->getData('state') == 2}checked{/if} title="审核通过">
                        <input type="radio" name="state" value="3" {if $info->getData('state') == 3}checked{/if} title="审核不通过">
                        <input type="radio" name="state" value="4" {if $info->getData('state') == 4}checked{/if} title="下架">
                    </div>
                </div>
                {:token()}
                <input type="hidden" value="{$act}" name="act" />
                <input type="hidden" value="{$info['id']|default=''}" name="id" />
                <input type="hidden" value="{$info->driving_license ? $info->getData('driving_license') : ''}" name="driving_license" />
                <input type="hidden" value="{$img_str}" name="img_url" id="img_url"/>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
                </div>
                <!--<div class="layui-form-item layui-layout-admin">-->
                <!--<div class="layui-input-block">-->
                <!--<div class="layui-footer" style="left: 0;">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>-->
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
            </form>
        </div>
    </div>
</div>


<script>
    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,upload = layui.upload;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#begin_time'
            ,type: 'date'
        });


        upload.render({
            elem: '#driving_license_btn'
            ,url: "{:url('common/upload_img')}"
            ,data: {src_name:'bus'}
            ,accept: 'images'
            ,acceptMime: 'image/*,image/gif'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#driving_license_img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    $('#driving_license_img').attr('src', " ");
                    layer.msg('上传失败');
                } else{
                    $("input[name='driving_license']").val(res.data);
                    layer.msg('上传成功');
                }
                //上传成功
            }
            // ,error: function(){
            //     //演示失败状态，并实现重传
            //     var demoText = $('#test-upload-demoText');
            //     demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            //     demoText.find('.demo-reload').on('click', function(){
            //         uploadInst.upload();
            //     });
            // }
        });

        $('#pic-list').viewer();

        $(".demo-reload").click(function () {
            $(this).parents('.layui-col-xs3').remove();//模拟前端删除按钮
            var img_urls = [];
            $(".layui-upload-img").each(function () {
                img_urls.push($(this).attr("data-src"));
            });
            $("#img_url").val(img_urls);
        });

        form.render(null, 'component-form-group');

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#bus_img_btn'
            , url: "{:url('common/upload_img')}"
            , data: {src_name:'bus'}
            , accept: 'images'
            , acceptMime: 'image/*,image/gif'
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                else {
                    $('#pic-list').append('<div class="layui-col-xs3">' +
                        '<img src="/uploads/' + res.data + '" class="layui-upload-img" data-src="' + res.data + '"">' +
                        '<p><button type="button" class="layui-btn layui-btn-xs demo-reload">删除</button></p></div>');

                    $(".demo-reload").click(function () {
                        $(this).parents('.layui-col-xs3').remove();//模拟前端删除按钮
                        var img_urls = [];
                        $(".layui-upload-img").each(function () {
                            img_urls.push($(this).attr("data-src"));
                        });
                        $("#img_url").val(img_urls);
                    });
                    var img_urls = [];
                    $(".layui-upload-img").each(function () {
                        img_urls.push($(this).attr("data-src"));
                    });
                    $("#img_url").val(img_urls);
                }
            }
            , error: function () {
            }
        });

    });

    function openImg(i) {
        layer.photos({
            photos: '#pic-list'
        });
    }
</script>
{/block}